package com.tankgame.its381b;

import java.io.IOException;
import java.util.Random;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author open
 */
public class BossSprite extends Sprite {
	
	// creates a static random variable r
    private static Random r;

    // creates the values width and height in regards to the image that will be used for the boss sprite
    private static final int WIDTH = 29, HEIGHT = 24;

    // creating the boss sprite
    public BossSprite() throws IOException {
    	//created with the image boss.png and a predefined with and height
        super(Image.createImage("/res/boss.png"), WIDTH, HEIGHT);
        //sets a reference pixel within the sprite
        defineReferencePixel(getWidth() / 2, getHeight());
        //generates a random value if none are present
        if( r == null ) {
            r = new Random();
        }
        //sets randomw to any value from 0 to the Max value of screen width minus the sprites width (ie 160-29=131)
        int randomw = (r.nextInt(Bounds.WIDTH-WIDTH));
        //sets the position where the sprite is created to randomw and 30
        setPosition(randomw, 30);
    }

    //move class for boss sprite
    public void move() {
    //calls the next frame in the sprite image to create an animation effect
    nextFrame();
    
      //sets the xdelta and ydelta values to random numbers within a range
      int xdelta = r.nextInt(8) - 4; // -2, -1, 0, 1, 2
      int ydelta = r.nextInt(2);     // 0, 1,
      
      //checks the location of the boss sprite in regards to the X axis and sets xdelta to O if sprite is near the edge
      if((this.getX()+xdelta)<=0) {
          xdelta = 0;
      }
      if((this.getX()+xdelta)>=(Bounds.WIDTH-WIDTH)) {
          xdelta = 0;
      }
      //tells the sprite to move according to the xdelta adn ydelta values
      move(xdelta, ydelta);
    }
}